<?php
class View_Bug_Manager_Assignment extends CMF_Krypton_Core_View
{
	/**
	 *	Contructs HTML Output.
	 *	@access		public
	 *	@return		string
	 */
	public function buildContent()
	{
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$words		= $this->words['bug']['assign'];

		if( $bug_id	= $request->get( 'bug_id' ) )
		{
			$bug	= new Bug( $bug_id );
			$data	= $bug->getData( TRUE );

			$user	= new User( $data['author'] );
			$author	= $user->getUsername();

			//  --  DEVELOPER ASSIGNMENTS  --  //
			$assign		= new Assignment();
			$assign->focusForeign( "bug_id", $bug_id );
			$has		= $assign->getData( FALSE );
			$list_has		= array();
			foreach( $has as $is )
				$list_has[]	= $is['user_id'];
			$userobj	= new User();
			$users	= $user->getAllData();
			$opt_developers	= $opt_developers_has	= array();

			$opt_developers		= array();
			$opt_developers_has	= array();
			foreach( $users as $user )
				if( $userobj->hasRole( $user['user_id'], 3 ) )		//  is a Developer
				{
					$target	= in_array( $user['user_id'], $list_has ) ? "opt_developers_has" : "opt_developers";
					${$target}[$user['user_id']]	= $user['username'];
				}
			$sources	= array(
				'opt_developers'		=> $opt_developers,
				'opt_developers_has'	=> $opt_developers_has,
				);

			$ui	= $this->buildForm( 'bug', 'editAssignment', 'bug', 'assign', $data, $sources );

			$button_add			= $this->html->Button( 'addDeveloper', $words['button_add'], 'but add' );
			$button_remove		= $this->html->Button( 'removeDeveloper', $words['button_remove'], 'buthot remove', $words['button_remove_confirm'] );
			$ui['field_button_add']		= $this->html->Field( '', $button_add );
			$ui['field_button_remove']	= $this->html->Field( '', $button_remove );

			$ui['form']		= $this->html->Form( 'assignBug', "?link=".$request->get( 'link' )."&bug_id=".$request->get( 'bug_id' ) );
			$ui['colgroup']		= $this->html->ColumnGroup( "50%", "50%" );
			$ui['caption']		= $this->html->TableCaption( $words['caption'] );
			$ui['heading']		= $words['heading'];

			return $this->loadTemplate( 'bug.edit_assign', $ui );
		}
		else
			$this->messenger->noteError( $this->words['bug']['msg']['error1'] );
	}
}
?>